package com.gitee.wsl.security.encrypt


import com.gitee.wsl.ext.string.toBinaryString
import com.gitee.wsl.security.encrypt.sm4.SM4Utils
import kotlin.test.Test

class SM4Test {

    fun testasdf(){
        "sdf"
    }

    @Test
    fun SM4Test() {
        val plainText = "I Love You Every Day"
        val s: String = plainText.toBinaryString()
        println("原文$s")
        val sm4: SM4Utils = SM4Utils()
        //sm4.secretKey = "JeF8U9wHFOMfs2Y8";
        sm4.secretKey = "64EC7C763AB7BF64E2D75FF83A319918"
        sm4.hexString = true

        println("ECB模式加密")
        val cipherText = sm4.encryptData_ECB(plainText)!!
        println("密文: $cipherText")
        println("")

        val plainText2 = sm4.decryptData_ECB(cipherText)
        println("明文: $plainText2")
        println("")

        println("CBC模式加密,安全性更高")
        sm4.iv = "31313131313131313131313131313131"
        val cipherText2 = sm4.encryptData_CBC(plainText)!!
        println("加密密文: $cipherText2")
        println("")

        val plainText3 = sm4.decryptData_CBC(cipherText2)
        println("解密明文: $plainText3")
    }
}